package com.lsz.crm.config;

import com.lsz.crm.exceptions.NoLoginException;
import com.lsz.crm.interceptor.NoLoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author liushizhong
 * @Date 2021/10/9 22:31
 * @Version 1.0
 */

/**
 * 实现 WebMvcConfigurer 并重写 addInterceptors，同时在这个方法里设置要过滤的URL
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Bean
    public NoLoginInterceptor noLoginInterceptor(){
        return new NoLoginInterceptor();
    }

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 加入实现拦截器对象的实例
        registry.addInterceptor(noLoginInterceptor())
                // 添加拦截路径
                .addPathPatterns("/**") // 默认拦截所有
                // 设置不要拦截的路径
                .excludePathPatterns("/css/**","/images/**","/js/**","/lib/**","/index","/user/login");
    }
}
